package com.example.springbean.controller;

import com.example.springbean.model.Student;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Resource(name = "singleStudent")
    private Student singleStudent;
    @Resource(name = "prototypeStudent")
    private Student prototypeStudent;
    @Resource(name = "requestStudent")
    private Student requestStudent;
    @Resource(name = "sessionStudent")
    private Student sessionStudent;
    @Resource(name = "applicationStudent")
    private Student applicationStudent;
    @Autowired
    private ApplicationContext context;

    @RequestMapping("/single")
    public String single() {
        Student student1 = (Student) context.getBean("singleStudent");
        return "student: " + singleStudent + "</br> contextStudent: " + student1;
    }

    @RequestMapping("/prototype")
    public String prototype() {
        Student student1 = (Student) context.getBean("prototypeStudent");
        return "student: " + prototypeStudent + "</br> contextStudent: " + student1;
    }

    @RequestMapping("/request")
    public String request() {
        Student student1 = (Student) context.getBean("requestStudent");
        return "student: " + requestStudent + "</br> contextStudent: " + student1;
    }

    @RequestMapping("/session")
    public String session() {
        Student student1 = (Student) context.getBean("sessionStudent");
        return "student: " + sessionStudent + "</br> contextStudent: " + student1;
    }

    @RequestMapping("/application")
    public String application() {
        Student student1 = (Student) context.getBean("applicationStudent");
        return "student: " + applicationStudent + "</br> contextStudent: " + student1;
    }
}
